package com.cdgeekcamp.redas.wechat.controller;

import com.cdgeekcamp.redas.wechat.aes.AesException;
import com.cdgeekcamp.redas.wechat.aes.WXBizMsgCrypt;
import com.cdgeekcamp.redas.wechat.config.WeChatConfig;
import com.cdgeekcamp.redas.wechat.service.WeChatService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@Controller
@RequestMapping(value = "/")
public class WeChatController {

    @Autowired
    private WeChatService weChatService;

    @GetMapping(value = "")
    public void verifyWeChatToken(HttpServletRequest request, HttpServletResponse response) throws Exception {

        weChatService.verifyComeFromWeChat(request, response);
    }

    @PostMapping(value = "")
    public void messageHandler(HttpServletRequest request, HttpServletResponse response,
                                  @RequestBody(required = false) String requestBody) throws Exception {

        weChatService.dealWithMessage(request, response, requestBody);
    }
}
